home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / ispell-3.1.18src / unsq.c < prev    next >
C/C++ Source or Header  |  1994-01-25  |  4KB  |  128 lines

  1. #ifndef lint
  2. static char Rcs_Id[] =
  3.     "$Id: unsq.c,v 1.14 1994/01/25 07:12:19 geoff Exp $";
  4. #endif
  5.  
  6. /*
  7.  * Copyright 1993, Geoff Kuenning, Granada Hills, CA
  8.  * All rights reserved.
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  *
  14.  * 1. Redistributions of source code must retain the above copyright
  15.  *    notice, this list of conditions and the following disclaimer.
  16.  * 2. Redistributions in binary form must reproduce the above copyright
  17.  *    notice, this list of conditions and the following disclaimer in the
  18.  *    documentation and/or other materials provided with the distribution.
  19.  * 3. All modifications to the source code must be clearly marked as
  20.  *    such.  Binary redistributions based on modified source code
  21.  *    must be clearly marked as modified versions in the documentation
  22.  *    and/or other materials provided with the distribution.
  23.  * 4. All advertising materials mentioning features or use of this software
  24.  *    must display the following acknowledgment:
  25.  *      This product includes software developed by Geoff Kuenning and
  26.  *      other unpaid contributors.
  27.  * 5. The name of Geoff Kuenning may not be used to endorse or promote
  28.  *    products derived from this software without specific prior
  29.  *    written permission.
  30.  *
  31.  * THIS SOFTWARE IS PROVIDED BY GEOFF KUENNING AND CONTRIBUTORS ``AS IS'' AND
  32.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  33.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  34.  * ARE DISCLAIMED.  IN NO EVENT SHALL GEOFF KUENNING OR CONTRIBUTORS BE LIABLE
  35.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  39.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  40.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  41.  * SUCH DAMAGE.
  42.  */
  43.  
  44. /*
  45.  * $Log: unsq.c,v $
  46.  * Revision 1.14  1994/01/25  07:12:19  geoff
  47.  * Get rid of all old RCS log lines in preparation for the 3.1 release.
  48.  *
  49.  */
  50.  
  51. #include <stdio.h>
  52. #include "msgs.h"
  53.  
  54. #ifdef __STDC__
  55. #define P(x)    x
  56. #else /* __STDC__ */
  57. #define P(x)    ()
  58. #endif /* __STDC__ */
  59.  
  60. int        main P ((int argc, char * argv[]));
  61. static int    expand P ((char * word, char * prev));
  62.  
  63. /*
  64.  * The following table encodes prefix sizes as a single character.  A
  65.  * matching table will be found in sq.c.
  66.  */
  67. static char size_encodings[] =
  68.     {
  69.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',    /* 00-09 */
  70.     'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',    /* 10-19 */
  71.     'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',    /* 20-29 */
  72.     'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',    /* 30-39 */
  73.     'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',    /* 40-49 */
  74.     'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',    /* 50-59 */
  75.     'y', 'z'                        /* 60-61 */
  76.     };
  77.  
  78. #define MAX_PREFIX    (sizeof (size_encodings) - 1)
  79.  
  80. extern void    exit P ((int status));
  81.  
  82. int main (argc, argv)
  83.     int            argc;
  84.     char *        argv[];
  85.     {
  86.     char        word[257];
  87.     static char        prev[257] = "";
  88.  
  89.     while (!expand (word, prev))
  90.         puts (word);
  91.     return 0;
  92.     }
  93.  
  94. static int expand (word, prev) 
  95.     char *        word;
  96.     char *        prev;
  97.     {
  98.     register char *    wordp;
  99.     register char *    prevp;
  100.     register int    same_count;
  101.     register int    count_char;
  102.  
  103.     count_char = getchar ();
  104.     if (count_char == EOF)
  105.     return(1);
  106.     for (same_count = 0;
  107.       same_count < MAX_PREFIX  &&  size_encodings[same_count] != count_char;
  108.       same_count++)
  109.     ;
  110.     if (same_count == MAX_PREFIX)
  111.     {
  112.     (void) fprintf (stderr, UNSQ_C_BAD_COUNT, (unsigned int) count_char);
  113.     exit (1);
  114.     }
  115.     prevp = prev;
  116.     wordp = word;
  117.     while (same_count--)
  118.     *wordp++ = (*prevp++);
  119.     if (gets (wordp) == NULL)
  120.     {
  121.     (void) fprintf (stderr, UNSQ_C_SURPRISE_EOF);
  122.     exit (1);
  123.     }
  124.     (void) strcpy (prev, word);
  125.     return 0 ;
  126.     }
  127.  
  128.